import fetch from "@/utils/http";
import {
  AddRole,
  AddUser,
  BaanerResponse,
  EditRole,
  EditUser,
  RolesRoot,
  UserResponse
} from "./system";
/**
 * 获取角色列表
 */
export function getAllRole() {
  return fetch<RolesRoot>(
    "/system/role/list?pageNum=1&pageSize=100",
    "MANGMENT",
    {
      method: "get"
    }
  );
}
/**
 * 添加角色
 */
export function addRole(data: AddRole) {
  return fetch("/system/role", "MANGMENT", {
    method: "POST",
    body: JSON.stringify(data)
  });
}
/**
 * 删除角色
 */
export function delRole(id: number) {
  return fetch(`/system/role/${id}`, "MANGMENT", {
    method: "DELETE"
  });
}
/**
 * 编辑角色
 */
export function editRole(data: EditRole) {
  return fetch("/system/role", "MANGMENT", {
    method: "PUT",
    body: JSON.stringify(data)
  });
}

/**
 * 获取用户列表
 */
export function getUserList(query: { pageNum: number; pageSize: number }) {
  return fetch<UserResponse>(
    `/system/user/list?pageNum=${query.pageNum}&pageSize=${query.pageSize}`,
    "MANGMENT",
    {
      method: "get"
    }
  );
}
/**
 * 添加用户
 */
export function addUser(data: AddUser) {
  return fetch("system/user", "MANGMENT", {
    method: "POST",
    body: JSON.stringify(data)
  });
}
/**
 * 编辑用户
 */
export function editUser(data: EditUser) {
  return fetch("system/user", "MANGMENT", {
    method: "PUT",
    body: JSON.stringify(data)
  });
}
/**
 * 删除用户
 */

export function delUser(id: number) {
  return fetch(`/system/user/${id}`, "MANGMENT", {
    method: "DELETE"
  });
}
/**
 * 重置密码
 */
export function resetPassword(data: { password: string; userId: number }) {
  return fetch("system/user/resetPwd", "MANGMENT", {
    method: "PUT",
    body: JSON.stringify(data)
  });
}
/**
 * 获取用户角色
 */
export function getUserRole(id: number) {
  return fetch<any>(`/system/user/${id}`, "MANGMENT", {
    method: "get"
  });
}

/**
 * 添加轮播图
 */
export function addBaaner(data: { imgUrl: string }) {
  return fetch(`/system/chart`, "MANGMENT", {
    method: "post",
    body: JSON.stringify(data)
  });
}
/**
 * 删除播图
 */
export function delBaaner(id: number) {
  return fetch(`/system/chart/${id}`, "MANGMENT", {
    method: "DELETE"
  });
}
/**
 * 获取轮播图
 */
export function getBaaner() {
  return fetch<BaanerResponse>(
    `/system/chart/list?pageNum=0&pageSize=100`,
    "MANGMENT",
    {
      method: "get"
    }
  );
}
